import os

from cpapp.docker import Docker

IMAGE_NAME = 'docker.yizhoucp.cn/android-ci/ci:1.0.0'
CONTAINER_NAME = 'cp-android-app'

class Patcher:

    def __init__(self, app):
        self.app = app
        self.docker = Docker(app)

    def bsdiff(self, base, new, patch_file):
        tmp_diff = os.path.join('/tmp', os.path.basename(patch_file))
        cmd = 'bsdiff %s %s %s' % (base, new, tmp_diff)
        self.docker.run_cmd_in_container(cmd)
        cmd = 'docker cp %s:%s %s' % (CONTAINER_NAME, tmp_diff, patch_file)
        self.app.shell_run(cmd)

        cmd = 'rm -f %s' % (tmp_diff)
        self.docker.run_cmd_in_container(cmd)

